/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.fgv.tcc.fgv.imovel.dao;

import br.com.fgv.tcc.fgv.imovel.model.Usuario;
import br.com.fgv.tcc.fgv.imovel.util.HibernateUtil;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import static org.hibernate.criterion.Projections.id;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author diego
 */
public class UsuarioDao extends HibernateGenericDao {

    public UsuarioDao() {
        super(Usuario.class);
        setOrdenacao("nome");
    }

    public List recuperaClientes(Criteria crit) {
        return super.buscar(crit);
    }

    public Object logar(Usuario usuario) {
        Criteria c;
        try {
            c = HibernateUtil.getSessionFactory().openSession().createCriteria(Usuario.class);
            c.add(Restrictions.eq("login", usuario.getLogin()));
            c.add(Restrictions.eq("senha", usuario.getSenha()));

        } catch (HibernateException hibernateException) {
            throw hibernateException;

        }
        return c.uniqueResult();
    }

}
